package com.gitee.swsk33.algorithms.tree.binarytree;

import java.util.List;

/**
 * 二叉树的测试主类
 */
public class BinaryTreeTest {

	public static void main(String[] args) {
		BinaryTree<String> tree = new BinaryTree<>("A");
		// 建立左子树
		TreeNode<String> leftSubTreeA = new TreeNode<>("B");
		TreeNode<String> leftSubTreeB = new TreeNode<>("D");
		leftSubTreeB.setLeft(new TreeNode<>("F"));
		leftSubTreeA.setLeft(leftSubTreeB);
		leftSubTreeA.setRight(new TreeNode<>("E"));
		tree.getRoot().setLeft(leftSubTreeA);
		// 建立右子树
		TreeNode<String> rightSubTreeA = new TreeNode<>("C");
		rightSubTreeA.setLeft(new TreeNode<>("H"));
		TreeNode<String> rightSubTreeC = new TreeNode<>("G");
		rightSubTreeC.setLeft(new TreeNode<>("I"));
		rightSubTreeA.setRight(rightSubTreeC);
		tree.getRoot().setRight(rightSubTreeA);
		// 试一试遍历
		// 先序遍历
		List<String> pre = tree.preorderTraversal();
		System.out.print("先序遍历：");
		for (String s : pre) {
			System.out.print(s + " ");
		}
		System.out.println();
		// 中序遍历
		List<String> in = tree.inorderTraversal();
		System.out.print("中序遍历：");
		for (String s : in) {
			System.out.print(s + " ");
		}
		System.out.println();
		// 后序遍历
		List<String> post = tree.postorderTraversal();
		System.out.print("后序遍历：");
		for (String s : post) {
			System.out.print(s + " ");
		}
		System.out.println();
	}

}